/* eslint-disable prefer-const */
{
  function _base() {
    interface Person {
      name: string;
      age: number;
    }

    const xiaoming: Person = {
      name: 'xiaoming',
      age: 18
    }
    console.log(xiaoming)
  }

  function _optional() {
    interface Person {
      name: string;
      age: number;
      money?: number;
    }

    const xiaoming: Person = {
      name: 'xiaoming',
      age: 18
    }

    const xiaohong: Person = {
      name: 'xiaohong',
      age: 17,
      money: 10000
    }

    console.log(xiaoming)
    console.log(xiaohong)
  }

  function _readonly() {
    interface Person {
      name: string;
      readonly age: number;
    }

    const xiaohong: Person = {
      name: 'xiaohong',
      age: 17
    }
    console.log(xiaohong.age) //pass
    // xiaohong.age = 18  //报错
  }

  function _function() {
    interface Func {
      (name: string): string;
      age: number;
    }

    let func: Func
    const myFunc = function (name) {
      return ''
    }
    myFunc.age = 18
    func = myFunc
    console.log(func)
  }

  function _indexOf() {
    interface AnyObject {
      [key: string]: string;
      age: string; //pass
      // age: number; //报错，与索引类型不匹配
    }
    interface CustonArray {
      [index: number]: string;
    }

    const obj: AnyObject = {
      a: '1',
      b: '2',
      age: '18'
    }

    const arr: CustonArray = ['a', 'b', 'c']
    console.log(obj, arr)
  }

  function _class() {
    interface Person {
      name: string;
      age: number;
      getMoney(num: number): number;
    }

    class Xiaomin implements Person {
      name = 'xiaomin'
      age = 18
      getMoney(num) {
        return num * 10
      }
    }
  }


  function _classInstance() {
    interface PersonInstance {
      name: string;
      age: number;
    }

    interface Person {
      new(name: string, age: number): PersonInstance;
    }

    class Xiaohong implements PersonInstance {
      name: string
      age: number
      constructor(name: string, age: number) {
        this.name = name
        this.age = age
      }
    }

    const xiaohong: Person = Xiaohong
  }


  function _extends() {
    class Action {
      run = true;
    }
    interface Person {
      name: string;
      age: number;
    }
    interface Worker {
      workTime: number;
    }

    interface Teacher extends Person, Worker {
      job: string;
    }

    interface Man extends Action {
      sit: boolean;
    }

    const man: Man = {
      run: false,
      sit: true
    }

    const ciaohong: Teacher = {
      name: 'xiaohong',
      age: 25,
      job: 'teacher',
      workTime: 8
    }
  }

  // _base()
  //_optional()
  //_readonly()
  //_function()
  //_indexOf()
  //_class()
  //_classInstance()
  //_extends()
}
